package com.general.framework.job.starter;

import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.util.DateUtil;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Date;

public class TaskUtil {
    private static final Logger log = LoggerFactory.getLogger(TaskUtil.class);

    public TaskUtil() {
    }

    public static Long taskStart(String jobName, String param) {
        XxlJobHelper.log("{}:{}", new Object[]{jobName, param});
        log.info("===>Task Start:{}:{}", jobName, param);
        return System.currentTimeMillis();
    }

    public static void taskEnd(String jobName, String param, long startTime) {
        log.info("===>Task End:{}:{},{}ms", new Object[]{jobName, param, System.currentTimeMillis() - startTime});
    }

    public static Long getParamId(String param) {
        Long paramId = null;
        if (Strings.isNotBlank(param)) {
            paramId = Long.parseLong(param);
        }

        return paramId;
    }

    public static Date getParamDate(String param) {
        Date date = null;
        if (Strings.isNotBlank(param)) {
            date = DateUtil.parseDate(param);
        }

        return date;
    }
}
